checkToken();

function checkToken() {
    var systoken = sessionStorage.getItem('systoken');
    if (!systoken) {
        alert("请先登录!")
        window.location.href = "../../login.html"
    }
}

getOperationRecords();

$(".startSearch").click(function () {
    getOperationRecords();
});
/*查询模拟机培训记录*/
function getOperationRecords() {
    layui.use(['table', 'laypage', 'layer', 'laydate', 'jquery'], function () {
        var laypage = layui.laypage,
            layer = layui.layer,
            $ = layui.$,
            laydate = layui.laydate;
        var table = layui.table;

        laydate.render({
            elem: '.startTime',
            type: 'date'
        });
        laydate.render({
            elem: '.endTime',
            type: 'date'
        });
        laydate.render({
            elem: '.updateTime',
            type: 'date'
        });
        laydate.render({
            elem: '.date',
            type: 'date'
        });

        var id = $(".id").val();//模拟机实操记录编号
        var className = $(".className").val();//班级编号
        var operationType = $(".operationType option:selected").val();//实操类型:0雷达 1机场 2程序,
        var number = $(".number").val();//练习题编号
        var machineCode = $(".machineCode").val();//模拟机编号
        var totalScore = $(".totalScore").val();//总分数
        var comment = $(".comment").val();//评语
        var explain = $(".explain").val();//说明
        var date = $(".date").val();//日期
        var startTime = $(".startTime").val();//开始日期
        var endTime = $(".endTime").val();//结束日期
        var studentName = $(".studentName").val();//学生姓名
        var teacherName = $(".teacherName").val();//老师姓名
        var stamp = new Date().getTime();

        var param = {
            //		id:id,
            //      className:className,

            //machineCode:machineCode,
            //	totalScore:totalScore,
            //	comment:comment,
            //	explain:explain,
            //	date:date,
            endTime:endTime,
            startTime: startTime,
            operationType: operationType,
            studentName: studentName,
            teacherName: teacherName,
            number: number,
            stamp: stamp,
            version: 0,
            visit_plat: 1,
            visit_type: 0,
            is_used: 0
        };
        var url = path + "/operationRecords/getAll";
        var defaultpageSise = 10;
        window.ins1 = _render(defaultpageSise);

        function _render(pageSize) {
            var width = $(document).width();
            table.render({
                id: 'id',
                elem: '#moTest',
                height: 600,
                title: '模拟机培训记录',
                method: 'post',
                url: url,
                page: true,
                where: {param: JSON.stringify(param)},
                headers: {Authorization: sessionStorage.getItem('systoken')},
                skin: 'row',
                even: true,
                loading: false,
                parseData: function (res) {
                    var status = res.status;
                    var info = '';
                    if (status == '000') {
                        info = res.info
                    } else if (status == '001'||status=='007') {
                        info = res.rows
                    } else if (status == '401') {
                        info = '请您重新登录！';
                    }
                    return {
                        "code": res.status,
                        "msg": info,
                        "count": res.total,
                        "data": res.rows
                    };
                },
                done: function (res) {
                    $('#inp').val(pageSize);
                    $("#inp").on('blur', function () {
                        var inputVal = $("#inp").val();
                        _render(inputVal);
                    });
                },
                totalRow: true,
                limit: 30,
                width: width * 0.9,
                cols: [
                    [
                        {field: 'operationType', title: '培训科目', align: 'center',templet: '#operationType',width:80},
                        {field: 'studentName', title: '学员姓名', align: 'center',width:80},
                        {field: 'number', title: '习题编号', align: 'center',width:80},
                        {field: 'totalScore', title: '得分', align: 'center',width:80,totalRow: true},
                        {field:'id', title:'开始时间',align: 'center'},
                        {field:'id', title:'结束时间',align: 'center'},
                        {field:'id', title:'时长',align: 'center'},
                        // {field: 'date', title: '上课日期', align: 'center',width:160,totalRowText:'合计'},
                        // {field: 'teacherName', title: '教员姓名', align: 'center',width:80},
                    ]
                ],
                page: true,
                limit: pageSize,
                loading: true //请求数据时，是否显示loading
            });
        };

        //监听排序
        table.on('sort(moTest)', function (obj) {
            layer.msg('已经完成排序！ ' + obj.field + ' ' + obj.type);
            //服务端排序
            table.reload('moTest', {
                initSort: obj,
                //,page: {curr: 1}
                where: {
                    key: obj.field,
                    order: obj.type
                }
            });
        });

        var $ = layui.jquery,
            active = {
                parseTable: function () {
                    table.init('parse-table-demo', {
                        limit: 3
                    });
                },
                add: function () {
                    table.addRow('moTest')
                }
            };
        $('i').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $('.layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        })
    });
}